#include <iostream>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N],b[N];
LL n , m;
bool check(int x)
{
    LL v = m;
    for(int i = 1; i <= n; i++)
    {
        if(a[i] > x) continue;
        if(a[i] + v < x) return false;
        if(a[i] + b[i] >= x && v >= x - a[i])
        {
            v -= (x - a[i]);
        }
        else{
            return false;
        }
    }
    return true;
}
int main()
{
  cin >> n >> m;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) cin >> b[i];


  LL l = 1 , r = 2 * N;
  while(l < r)
  {
      LL mid = (l + r + 1) / 2;
      if(check(mid))
      {
          l = mid;
      }
      else
      {
          r = mid - 1;
      }
  }
  cout << r << endl;
  return 0;
}
